const IPregex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/

export const IPvalidator = (ip: string) => {
  // Pure IP validator
  return IPregex.test(ip)
}

export const IPvalidatorForEl = (rules: any, value: any, callback: any) => {
  if (IPvalidator(value)) {
    return callback()
  } else {
    return callback(new Error("IP地址格式错误！"))
  }
}
